<?php
//首页搜索，站内关键字搜索
function index()
{
	global $db,$results,$request;
	
	if(!checkSqlStr($request['keyword']))
	$request['keyword'] = $request['keyword'];
	else
	echo '非法字符';
	
	$keyword = urldecode($request['keyword']);
	if(empty($keyword))
	{
		echo '<script>alert("请输入您要查询的内容！");window.history.go(-1);</script>';
	}
	else
	{
		$sql = 'select * from '.TB_PREFIX.'models_reg';
		$modelName = $db->get_results($sql);
		foreach($modelName as $mname)
		{
			switch($mname->type)
			{
				case 'article':
					$searchResults = get_search_result($mname->type);
					if(!empty($searchResults))
					{
						foreach($searchResults as $o)
						{
							$results[] = array('id'=>$o->id,'type'=>'article','p'=>$o->channelId,'title'=>trimTags($o->pageName),'content'=>trimTags($o->content),'dtTime'=>$o->dtTime);
						}
					}
					break;
				case 'list':
					$searchResults = get_search_result($mname->type);
					if(!empty($searchResults))
					{
						foreach($searchResults as $o)
						{
							$results[] = array('id'=>$o->id,'type'=>'list','p'=>$o->channelId,'title'=>trimTags($o->title),'content'=>trimTags($o->content),'dtTime'=>$o->dtTime);
						}
					}
					break;		
				case 'product':
					$searchResults = get_search_result($mname->type);
					if(!empty($searchResults))
					{
						foreach($searchResults as $o)
						{
							$results[] = array('id'=>$o->id,'type'=>'product','p'=>$o->channelId,'title'=>trimTags($o->name),'content'=>trimTags($o->content),'dtTime'=>$o->dtTime);
						}
					}
					break;
				case 'download':
					$searchResults = get_search_result($mname->type);
					if(!empty($searchResults))
					{
						foreach($searchResults as $o)
						{
							$results[] = array('id'=>$o->id,'type'=>'download','p'=>$o->channelId,'title'=>trimTags($o->softwareName),'content'=>trimTags($o->introduce),'dtTime'=>$o->dtTime);
						}
					}
					break;	
				case 'picture':
					$searchResults = get_search_result($mname->type);
					if(!empty($searchResults))
					{
						foreach($searchResults as $o)
						{
							$results[] = array('id'=>$o->id,'type'=>'picture','p'=>$o->channelId,'title'=>trimTags($o->title),'content'=>trimTags($o->description),'dtTime'=>$o->dtTime);
						}
					}
					break;	
				case 'video':
					$searchResults = get_search_result($mname->type);
					if(!empty($searchResults))
					{
						foreach($searchResults as $o)
						{
							$results[] = array('id'=>$o->id,'type'=>'video','p'=>$o->channelId,'title'=>trimTags($o->title),'content'=>trimTags($o->description),'dtTime'=>$o->dtTime);
						}
					}
					break;	
				case 'tour':
					$searchResults = get_search_result($mname->type);
					if(!empty($searchResults))
					{
						foreach($searchResults as $o)
						{
							$results[] = array('id'=>$o->id,'type'=>'tour','p'=>$o->channelId,'title'=>trimTags($o->stars),'content'=>trimTags($o->things),'dtTime'=>$o->dtTime);
						}
					}
					break;	
				case 'special':
					$searchResults = get_search_result($mname->type);
					if(!empty($searchResults))
					{
						foreach($searchResults as $o)
						{
							$results[] = array('id'=>$o->id,'type'=>'special','p'=>$o->channelId,'title'=>trimTags($o->name),'content'=>trimTags($o->content),'dtTime'=>$o->dtTime);
						}
					}
					break;		
				case 'jobs':
					$searchResults = get_search_result($mname->type);
					if(!empty($searchResults))
					{
						foreach($searchResults as $o)
						{
							$results[] = array('id'=>$o->id,'type'=>'jobs','p'=>$o->channelId,'title'=>trimTags($o->jobName),'content'=>trimTags($o->summary),'dtTime'=>$o->dtTime);
						}
					}
					break;
				case 'recruitment':
					$searchResults = get_search_result($mname->type);
					if(!empty($searchResults))
					{
						foreach($searchResults as $o)
						{
							$results[] = array('id'=>$o->id,'type'=>'recruitment','p'=>$o->channelId,'title'=>trimTags($o->name),'content'=>trimTags($o->selfBriefly),'dtTime'=>$o->dtTime);
						}
					}
					break;	
				case 'solutions':
					$searchResults = get_search_result($mname->type);
					if(!empty($searchResults))
					{
						foreach($searchResults as $o)
						{
							$results[] = array('id'=>$o->id,'type'=>'solutions','p'=>$o->channelId,'title'=>trimTags($o->title),'content'=>trimTags($o->content),'dtTime'=>$o->dtTime);
						}
					}
					break;	
			}
		}
	}
}
function get_search_result($modelName)
{
	global $db,$request;
	$keyword = urldecode($request['keyword']);
	switch($modelName)
	{
		case 'article':
			$sql = "select * from `".TB_PREFIX."article` where pageName like '%$keyword%' or content like '%$keyword%' order by id desc";
			return $db->get_results($sql);
			break;
		case 'list':
			$sql="select * from `".TB_PREFIX."list` as a,`".TB_PREFIX."list_content` as b where a.guid=b.guid and (title like '%$keyword%' or content like '%$keyword%') order by id desc";
			return $db->get_results($sql);
			break;
		case 'product':
			$sql="select * from `".TB_PREFIX."product` where name like '%$keyword%' or content like '%$keyword%' order by id desc";
			return $db->get_results($sql);
			break;
		case 'download':
			$sql="select * from `".TB_PREFIX."download` where softwareName like '%$keyword%' or introduce like '%$keyword%' order by id desc";
			return $db->get_results($sql);
			break;
		case 'picture':
			$sql="select * from `".TB_PREFIX."picture` where title like '%$keyword%' or description like '%$keyword%' order by id desc";
			return $db->get_results($sql);
			break;
		case 'video':
			$sql="select * from `".TB_PREFIX."video` where title like '%$keyword%' or description like '%$keyword%' order by id desc";
			return $db->get_results($sql);
			break;
		case 'tour':
			$sql="select * from `".TB_PREFIX."tour` where stars like '%$keyword%' or things like '%$keyword%' order by id desc";
			return $db->get_results($sql);
			break;
		case 'special':
			$sql="select * from `".TB_PREFIX."special` where name like '%$keyword%' or content like '%keyword%' order by id desc";
			return $db->get_results($sql);
			break;
		case 'jobs':
			$sql="select * from `".TB_PREFIX."jobs` where jobName like '%$keyword%' or summary like '%$keyword%' order by id desc";
			return $db->get_results($sql);
			break;
		case 'recruitment':
			$sql="select * from `".TB_PREFIX."recruitment` where name like '%$keyword%' or selfBriefly like '%$keyword%' order by id desc";
			return $db->get_results($sql);
			break;
		case 'solutions':
			$sql="select * from `".TB_PREFIX."solutions` as a,`".TB_PREFIX."solutions_content` as b where a.guid=b.guid and (title like '%$keyword%' or content like '%$keyword%') order by id desc";
			return $db->get_results($sql);
			break;
	}
}
?>